var resourceCtroller = require('../controllers/acl_resource');
var session = {
    out: function(req, res, next) {
        // console.log(req.session)
        // return false;


        if (req.session.curUserId) {
            async.auto({
                //获取资源
                resources: function(cb) {
                    resourceCtroller.getList({}, function(err, resources) {
                        var resourceList = [];
                        if (resources) {
                            resources.forEach(function(item) {
                                resourceList.push(item.id);
                            });
                        }
                        cb(err, resourceList);
                    });
                },
                //获取权限
                permissions: ["resources", function(data, cb) {
                    //console.log("resources:",data.resources);
                    global.acl.allowedPermissions(req.session.curUserId, data.resources, cb);
                }],
            }, function(err, data) {
                req.session.curUserPerms = data.permissions;
                next();
            })
        }


    }
}
module.exports = session;